package com.dwjm.exam.stu_reg;

import com.dwjm.exam.pojo.Student;
import com.dwjm.exam.utils.ConnectionDatabaseForMySQLUseJdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class StudentRegisterDaoImpl implements StudentRegisterDao {
    Connection connection = null;
    PreparedStatement pstmt = null;
    ResultSet rset = null;
    public StudentRegisterDaoImpl(){
        connection = ConnectionDatabaseForMySQLUseJdbc.getConnection();

    }
//    @Override
//    public int reg(Student student) {
//        try{
//            pstmt = connection.prepareStatement("insert into student(account, password) values(?,?)");
//            pstmt.setString(1, student.getAccount());
//            pstmt.setString(2, student.getPassword());
//            int i = pstmt.executeUpdate();
//            return i;
//        }catch (Exception e){
//            e.printStackTrace();
//            return 0;
//        }
//
//    }




    @Override
    public boolean registerStudent(Student student) {
        try {
            pstmt = connection.prepareStatement("insert into student(username, password) values(?,?)");
            pstmt.setString(1, student.getUsername());
            pstmt.setString(2, student.getPassword());
            int i = pstmt.executeUpdate();
            return i == 1 ? true : false;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public boolean isUsernameExist(String username) {
        return false;
    }

    @Override
    public boolean isIdCardExist(int studentId) {
        return false;
    }
}
